package com.apache.tools;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

public class JSONTools {

	/**
	 * 把java对象转换成JSONObject
	 * @param obj
	 * @return net.sf.json.JSONObject
	 */
	public static net.sf.json.JSONObject getJSONObject(Object obj) {
		JsonConfig jsonConfig = new JsonConfig();
		jsonConfig.setExcludes(new String[] { "handler", "hibernateLazyInitializer" });
		return JSONObject.fromObject(obj, jsonConfig);
	}

	/**
	 * 把java对象转换成JSONArray
	 * @param obj
	 * @return net.sf.json.JSONArray
	 */
	public static net.sf.json.JSONArray getJSONArray(Object obj) {
		JsonConfig jsonConfig = new JsonConfig();
		jsonConfig.setExcludes(new String[] { "handler", "hibernateLazyInitializer" });
		return net.sf.json.JSONArray.fromObject(obj, jsonConfig);
	}

}
